<template>
  <div class="change-password-container">
    <el-card class="change-password-card">
      <template #header>
        <div class="card-header">
          <span>修改密码</span>
        </div>
      </template>
      
      <el-form
        ref="passwordForm"
        :model="passwordForm"
        :rules="rules"
        label-width="100px"
        class="password-form"
      >
        <el-form-item label="原密码" prop="oldPassword">
          <el-input
            v-model="passwordForm.oldPassword"
            type="password"
            placeholder="请输入原密码"
            show-password
          />
        </el-form-item>
        
        <el-form-item label="新密码" prop="newPassword">
          <el-input
            v-model="passwordForm.newPassword"
            type="password"
            placeholder="请输入新密码"
            show-password
          />
        </el-form-item>
        
        <el-form-item label="确认密码" prop="confirmPassword">
          <el-input
            v-model="passwordForm.confirmPassword"
            type="password"
            placeholder="请再次输入新密码"
            show-password
          />
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="handleSubmit">确认修改</el-button>
          <el-button @click="handleCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'ChangePassword',
  data() {
    const validateConfirmPassword = (rule, value, callback) => {
      if (value !== this.passwordForm.newPassword) {
        callback(new Error('两次输入的密码不一致'))
      } else {
        callback()
      }
    }
    
    return {
      passwordForm: {
        oldPassword: '',
        newPassword: '',
        confirmPassword: ''
      },
      rules: {
        oldPassword: [
          { required: true, message: '请输入原密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
        ],
        newPassword: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
        ],
        confirmPassword: [
          { required: true, message: '请再次输入新密码', trigger: 'blur' },
          { validator: validateConfirmPassword, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.passwordForm.validate((valid) => {
        if (valid) {
          // TODO: 这里添加修改密码的API调用
          this.$message({
            message: '密码修改成功',
            type: 'success'
          })
          this.$router.push('/home')
        }
      })
    },
    handleCancel() {
      this.$router.push('/home')
    }
  }
}
</script>

<style scoped>
.change-password-container {
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  max-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.change-password-card {
  width: 100%;
  max-width: 100%;
  height: 85vh;
  border-radius: 0;
  box-shadow: none;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
}

.change-password-card:hover {
  transform: none;
  box-shadow: none;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #ebeef5;
  background-color: #fff;
}

.card-header span {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
}

.password-form {
  margin: 0;
  padding: 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.el-form-item:last-child {
  margin-bottom: 0;
  text-align: center;
  margin-top: 40px;
}

.el-button {
  margin: 0 10px;
  padding: 12px 24px;
  font-size: 14px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.el-input {
  margin: 8px 0;
}

.el-input__inner {
  height: 40px;
  line-height: 40px;
  border-radius: 4px;
}

.el-form-item__label {
  font-weight: 500;
  color: #606266;
}
</style> 